<script type="text/javascript">
    var form_validation=true;
    function submit_snapshot_task(){
        var unit = $("#volume_snapshot_task").find(".snanpshot_check:checked").val()
        var task_select = $("#volume_snapshot_task").find("#snapshot_day_select");
        if (unit == 'days'){
            task_select = $("#volume_snapshot_task").find("#snapshot_day_select");
        }
        if (unit == 'hours'){
            task_select = $("#volume_snapshot_task").find("#snapshot_hour_select");
        }
        if (unit == 'minutes'){
            task_select = $("#volume_snapshot_task").find("#snapshot_minute_select");
        }
        var count = task_select.attr('realvalue');
        var unit_show = task_select.siblings(".unit_show").text();
     	var bValid = true;
//        bValid = snapshot_scale(capacity.val(),false);
        if (bValid) {
            $(".table .error_tip").hide();
          if(form_validation){
             $(".callback_error_tip").text("正在提交中......").css({"display":"block","color":'#000'});        
            form_validation=false;
            $.post("/snapshot_task",{
                        'unit':unit,
                        'count':count,
                        'volume_id':"{{ volume.id }}",
                        },
                    function(data){
                        if (data.reply.is_success){
                            msg = "快照任务设置完成";
                            $(".callback_error_tip").css("display","block");
                            $(".callback_error_tip").text(msg);
                            $(".snapshot_cycle").text(count + unit_show)
                        }else{
                            error =  data.reply.error;
                            $(".callback_error_tip").css("display","block");
                            $(".callback_error_tip").text(error);
                        }
                        form_validation=true;                           
                 });
           }
          else
          {
             $(".callback_error_tip").text("正在提交中......").css({"display":"block","color":'#000'});        
           }
        }
    }
    $(".snanpshot_check").click(function(){
        method = $("#volume_snapshot_task").find(".snanpshot_check:checked").val();
        if (method == 'hours'){
            $(".cycle_"+method).css("display", "");
            $(".cycle_days").css("display", "none");
            $(".cycle_minutes").css("display", "none");
        }
        if (method == 'days'){
            $(".cycle_"+method).css("display", "");
            $(".cycle_hours").css("display", "none");
            $(".cycle_minutes").css("display", "none");
        }
        if (method == 'minutes'){
            $(".cycle_minutes").css("display", "");
            $(".cycle_hours").css("display", "none");
            $(".cycle_days").css("display", "none");
        }
    })
    $(".snanpshot_task_submit").click(function(){
        submit_snapshot_task(); 
    })
    
    days = []
    for (var i=1; i< 31; i++){
        days.push([i, i])
    }
     $('#snapshot_day_select').rqDropDown({
        "datatype":"local",
        "source":days,
//        "onchange":""
    }); 
    hours=[]
    for (var i=1; i< 24; i++){
        hours.push([i, i])
    }
     $('#snapshot_hour_select').rqDropDown({
        "datatype":"local",
        "source":hours,
//        "onchange":""
    }); 
    minutes = []
    for (var i=5; i< 60; i +=5){
        minutes.push([i, i])
    }
     $('#snapshot_minute_select').rqDropDown({
        "datatype":"local",
        "source":minutes,
//        "onchange":""
    }); 
</script>
<style>
.table .tb-item-value > div:first-child{margin-bottom:5px;color:#666}
</style>
<div class="modal-header">  
    <h3>创建快照</h3>  
</div> 
<div  class="modal-body"  id="volume_snapshot_task">
<div id="dialog_snapshot_create" title="创建快照">  
    <!--<div class="error_tip"></div>-->
    <form id="snapshot_add_form">
    <p>&nbsp;带<a class="high_tip_red">*</a>号的必填项</p>
    <div class="callback_error_tip error_tip"></div>            
    <div class="error_tip"></div>
    <table class="table">
        <tr>
            <td class="tb-item-name"><label for="snanpshot_check">重复方式:</label><a>*</a></td>
            <td class="tb-item-value">
         	 	<div class="error_tip"></div>
          		<input class="snanpshot_check" name="snanpshot_check" size="25" type="radio" value="days" checked="checked"/><span>按天重复</span>    &nbsp;
          		<input class="snanpshot_check" name="snanpshot_check" size="25" type="radio" value="hours"/><span>按小时重复</span>&nbsp;
          		<input class="snanpshot_check" name="snanpshot_check" size="25" type="radio" value="minutes"/><span>按分钟重复</span>&nbsp;
            </td>             
        </tr>
        <tr class="tr-back cycle_days" >
            <td class="tb-item-name"><label for="snanpshot_check">重复周期:</label><a>*</a></td>
            <td class="tb-item-value">
            <div class="error_tip"></div>
            <input id="snapshot_day_select"  class="rounded_dropdown" readonly="readonly"  style="width:100px;" value="1" realvalue='1'/> <span class="unit_show">天</span>
        </tr>
        <tr class="tr-back cycle_hours" style='display:none'>
            <td class="tb-item-name"><label for="snanpshot_check">重复周期:</label><a>*</a></td>
            <td class="tb-item-value">
            <div class="error_tip"></div>
            <input id="snapshot_hour_select"  class="rounded_dropdown" readonly="readonly"  style="width:100px;" value="1" realvalue='1'/> <span class="unit_show">小时</span>
        </tr>
        <tr class="tr-back cycle_minutes" style='display:none'>
            <td class="tb-item-name"><label for="snanpshot_check">重复周期:</label><a>*</a></td>
            <td class="tb-item-value">
            <div class="error_tip"></div>
            <input id="snapshot_minute_select"  class="rounded_dropdown" readonly="readonly"  style="width:100px;" value="5" realvalue='5'/> <span class="unit_show">分钟 </span>
        </tr>
        <tr>
            <td class="tb-item-name"><label for="snanpshot_check"></label><a></a></td>
            <td class="tb-item-value">
            <div class="error_tip"></div>
            <input class="snanpshot_task_submit button button_gray" name="snanpshot_task" size="25" type="button" value="设置"/>
        </tr>
    </table>
    </form>
    {% if volume.snapshot_cycle %}
        已设置定时任务周期: <span class="snapshot_cycle">{{ volume.snapshot_cycle }}</span>
    {% else %}
        已设置定时任务周期: <span class="snapshot_cycle">未设置</span>
    {% endif %}
</div>
<div id='warn_size_confirm' >
</div>
</div>
<div class="modal-footer">  
    <button class="button button_gray" ng-click="cancel()">[[ 'label cancel'|translate ]]</button>  
</div>
